<?php
include_once "includes.php";
include_once "libs/Sajax.php";

function getParameters_($srv)
{
		$param = new parametro();
		return $param->find_by_servicio($srv->id);
}	

function getReturns_($srv)
{
		$param = new parametro();
		return $param->find_returns_by_servicio($srv->id);
}
	
function traerParametros($txt) 
{
	$list = split(",", $txt);
	$srvId = $list[0];
	$where = $list[1];

	if ($srvId == 0)
		return "nulo";
		
	$Servicio = new servicio();
	$srv = $Servicio->find_by_id($srvId);

	foreach( $srv as $s )
	{
		if ( $where == "desde" && $s->interno == "0" || $where == "hasta" && $s->interno == "1" )
		{
			$params = getParameters_($s);
		}
		else if( $where == "desde" && $s->interno == "1" || $where == "hasta" && $s->interno == "0" )
		{
			$params = getReturns_($s);
		}
		else
			return "Hay un error";
						
		// Comienzo a imprimir el select
		$salida = count($params).',';
		foreach ($params as $p) 
		{
			$tipo = getTipo($p->tipo);
			$salida = $salida."<option value='$p->id'>$tipo: $p->nombre</option>";
		}

	}

	return $salida;
}

sajax_init();
sajax_export("traerParametros");
sajax_handle_client_request();
 
?>
